package com.breakfast.fun.ui.user.info;

import com.breakfast.fun.Constant;
import com.breakfast.fun.data.entity.user.User;
import com.breakfast.fun.util.Api;
import com.breakfast.fun.util.RxSchedulers;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.http.FieldMap;
import rx.Observable;

/**
 * Created by yukai on 16/9/20.
 */
public class UserInfoModel implements UserInfoContract.Model {
    @Override
    public Observable<User> uploadPhotoModel(File file) {
        RequestBody requestFile =
                RequestBody.create(MediaType.parse("image/jpg"), file);

        RequestBody id = RequestBody.create(MediaType.parse("text/plain"), Constant.getUserData().getId() + "");

        Map<String, RequestBody> map = new HashMap<>();
        map.put("image\"; filename=\"" + file.getName() + "", requestFile);
        map.put("id", id);
        return Api.getInstance().service
                .getUploadPhotoModel(map)
                .compose(RxSchedulers.io_main());
    }

    @Override
    public Observable<User> getSaveInfoModel(@FieldMap Map<String, String> map) {
        return Api.getInstance().service
                .getSaveUserInfoModel(map)
                .compose(RxSchedulers.io_main());
    }


}
